package repository.impl;

import DB.DBConnection;
import entity.Reader;
import repository.ReaderRepository;

import java.sql.*;



public class ReaderRepositoryImpl implements ReaderRepository {
    Connection conncetion=null;
    PreparedStatement statement=null;
    ResultSet resultSet=null;
    @Override
    public Reader login(String username, String password) throws SQLException, ClassNotFoundException {
        String sql="select * from reader where username=?";
        Reader reader=new Reader();
        try {
            conncetion=DBConnection.getDB();
            statement=conncetion.prepareStatement(sql);
            resultSet=statement.executeQuery();
            while(resultSet.next())
            {
                reader.setUsername(resultSet.getString("2"));
                reader.setPassword(resultSet.getString(3));
            }

        } finally {
            DBConnection.closeConncetion(conncetion,statement,resultSet);
        }
        return reader;

    }
}
